
// 1.导入mockjs
import Mock, { Random } from 'mockjs'
import _ from 'lodash'

export const setItem = (key, value) => {
  // 将数组、对象类型的数据转换为 JSON 格式字符串进行存储
  if (typeof value === 'object') {
    value = JSON.stringify(value)
  }
  window.localStorage.setItem(key, value)
}
/**
 * 获取数据
 */
export const getItem = key => {
  // 假设data得到的就是 ''
  const data = window.localStorage.getItem(key)
  try {
    return JSON.parse(data)
  } catch (err) {
    return null
  }
}

Mock.mock('/homeserver/master', 'get', function () {
})

Mock.mock('/homehelp/master', 'get', function () {
})

Mock.mock('/domesserverice/master', 'post', function () {
})

Mock.Random.extend({
  // 图片
  imgs: () => {
    const arrr = Mock.Random.dataImage()
    return arrr
  }
})
Mock.Random.extend({
  gongsi: () => {
    return (
      '湖南省' + Mock.Random.cword(5, 7) + '服务有限公司'
    )
  },
  picc: () => {
    const arr = [
      'https://images.cnblogs.com/cnblogs_com/wsm777/1862462/o_201013105509%E5%9B%A2%E9%98%9F%E9%A3%8E%E9%87%8701.jpg',
      'https://images.cnblogs.com/cnblogs_com/wsm777/1862462/o_201013105337%E5%8A%9E%E5%85%AC%E7%8E%AF%E5%A2%8302.jpg',
      'https://images.cnblogs.com/cnblogs_com/wsm777/1862462/o_201013105331%E5%8A%9E%E5%85%AC%E7%8E%AF%E5%A2%8301.jpg'
    ]
    return _.sample(arr)
  }

})
Mock.mock('/getmanylist', 'get', () => {
  console.log(111);
  const data = Mock.mock({
    'list|3': [{
      'id|+1': 1,
      company: '@gongsi()',
      photolist: '@picc()'
    }]
  })
  return data
})
// Mock.mock('/getphoto', 'get', () => {
//   const data = Mock.mock({
//     'list'
//   })
// })
// Mock.mock('@county(true)').extend({
//   job: function () {
//     const arr = ['武汉', '郑州', '广州']
//     return this.pick(arr)
//   }
// })
